package chapter3.lc167;

//LC 167

/**
 * 2sum的双指针版本
 */
public class TwoSumOrdered {
    public int[] twoSum(int[] numbers, int target) {
        int left = 0, right = numbers.length -1;
        while (left < right) {
            if (numbers[left] + numbers[right] == target) {
                return new int[]{left + 1, right + 1};
            }else if(numbers[left] + numbers[right] < target) {
                left++;
            }else {
                right--;
            }
        }
        throw new IllegalArgumentException("no solution");
    }
}
